<%@ page contentType="text/html; charset=UTF-8"%>
<jsp:include page="pages/common/all-js-css.jsp"></jsp:include>

<div id='lemonMenu'>
	<ul id="lemonMenu_tree" class="tree jd_menu" ></ul>
</div>
<script>
	var setting = {
		isSimpleData : true, //数据是否采用简单 Array 格式，默认false  
		treeNodeKey : "id", //在isSimpleData格式下，当前节点id属性  
		treeNodeParentKey : "pId", //在isSimpleData格式下，当前节点的父节点id属性  
		showLine : true
	//是否显示节点间的连线  
	// checkable : true                  //每个节点上是否显示 CheckBox
	};
	$.ajax({
		type : 'POST',
		dataType : "html",
		url : 'goal/menu.action',
		error : function() {
			alert('请求失败');
		},
		success : function(data) {
			var treeNodes = eval(data);
			var $portletTree = $("#lemonMenu_tree");
			// generate the ul li list
			var zTree = $portletTree.zTree(setting, treeNodes);
			// remove unuse element generate by ztree
			$portletTree.find('div').remove();
			$portletTree.find('button').remove();
			$portletTree.removeClass('tree');
			// remove the span and hiden ul by ztree
			$portletTree.find('span').each(function(){
				var $span = $(this);
				var $a = $span.parent();
				var $ul_hide = $a.next();
				var urlName = $span.text();
				$a.removeAttr('target');
				if(!($ul_hide.children().length > 0))
					$ul_hide.remove();
				$span.parent().empty().text(urlName);
			});
			
			var ul = $('#lemonMenu').html() ;
			$('#lemonMenu').empty();
			$('#lemonMenu').append(ul);
			$('ul.jd_menu').jdMenu();
		}
	});
</script>

